home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / lysrc.zip / LEXLIST.PAS < prev    next >
Pascal/Delphi Source File  |  1993-01-24  |  3KB  |  113 lines

  1.  
  2. unit LexList;
  3.  
  4. (* 1-26-91 AG *)
  5.  
  6. (* Copyright (c) 1990,91 by Albert Graef, Schillerstr. 18,
  7.    6509 Schornsheim/Germany
  8.    All rights reserved *)
  9.  
  10. interface
  11.  
  12. uses LexBase;
  13.  
  14. (* Lex listing routines.
  15.  
  16.    This module provides some routines to produce a readable representation
  17.    of the generated DFA tables (the routines are only used when Lex is run
  18.    with the verbose option /v).
  19.  
  20.    If this module is compiled with defined conditional `debug', the list file
  21.    will contain extensive debugging output (position table, state positions,
  22.    etc.). *)
  23.  
  24. procedure listDFATable;
  25.   (* list DFA table *)
  26.  
  27. implementation
  28.  
  29. uses LexTables;
  30.  
  31. procedure listTrans(cc : CClassPtr; next_state : Integer);
  32.   (* list a transition in the format
  33.         cc : next_state *)
  34.   begin
  35.     write(yylst, cclassOrCharStr(cc^):30, ' : ', next_state:5);
  36.   end(*listTrans*);
  37.  
  38. {$ifdef debug}
  39.  
  40. procedure listPosTable;
  41.   (* lists the position table *)
  42.   var
  43.     p, i : Integer;
  44.   begin
  45.     if n_pos=0 then exit;
  46.     writeln(yylst);
  47.     for p := 1 to n_pos do
  48.       with pos_table^[p] do
  49.         begin
  50.       write(yylst, p:5, '     ');
  51.           if pos_type=char_pos then
  52.             write(yylst, singleQuoteStr(c):20)
  53.           else if pos_type=cclass_pos then
  54.             write(yylst, cclassStr(cc^):20)
  55.       else if pos_type=mark_pos then
  56.         if pos=0 then
  57.           write(yylst, '# (rule '+intStr(rule)+')':20)
  58.         else
  59.           write(yylst, '/ (rule '+intStr(rule)+')':20);
  60.           write(yylst, ' ':5);
  61.           for i := 1 to size(follow_pos^) do
  62.             if follow_pos^[i]>0 then write(yylst, follow_pos^[i]:5, ' ');
  63.           writeln(yylst);
  64.         end;
  65.     writeln(yylst);
  66.   end(*listPosTable*);
  67.  
  68. {$endif}
  69.  
  70. procedure listDFATable;
  71.   var k, state : Integer;
  72.   begin
  73. {$ifdef debug}
  74.     (* list position table: *)
  75.     writeln(yylst);
  76.     writeln(yylst, '( positions : )');
  77.     listPosTable;
  78.     (* list state table: *)
  79.     writeln(yylst);
  80.     writeln(yylst, '( states : )');
  81. {$endif}
  82.     writeln(yylst);
  83.     for state := 0 to pred(n_states) do
  84.       begin
  85.         writeln(yylst);
  86.         write(yylst, state);
  87.         with state_table^[state] do
  88.           begin
  89.             if final then
  90.               write(yylst, '* :')
  91.             else
  92.               write(yylst, '  :');
  93. {$ifdef debug}
  94.             for k := 1 to size(state_pos^) do
  95.               write(yylst, ' ', state_pos^[k]:5);
  96. {$else}
  97.             for k := 1 to size(state_pos^) do
  98.               with pos_table^[state_pos^[k]] do
  99.         if (pos_type=mark_pos) and (pos=0) then
  100.                   write(yylst, ' ', rule:5);
  101. {$endif}
  102.             writeln(yylst);
  103.             for k := trans_lo to trans_hi do
  104.               with trans_table^[k] do
  105.                 begin
  106.                   listTrans(cc, next_state);
  107.                   writeln(yylst);
  108.                 end;
  109.           end;
  110.       end;
  111.   end(*listDFATable*);
  112.  
  113. end(*LexList*).